using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;

namespace SimplePoker.Main
{
    public class Deck
    {
        public int Count { get { return 13; } }
        private IList<Card> _CardsLeft;
        public IEnumerable<Card> CardsLeft
        {
            get
            {
                return _CardsLeft;
            }
        }

        public Deck()
        {
            _CardsLeft = new List<Card>();
            for (int i = 1; i < 14; i++)
            {
                _CardsLeft.Add(new Card(i));
            }
        }

        public Card TakeCard()
        {
            var c = _CardsLeft.FirstOrDefault();
            _CardsLeft.Remove(c);
            return c;
        }

        private Card Remove(int rank)
        {
            var card = _CardsLeft.FirstOrDefault(c => c.Rank == rank);
            _CardsLeft.Remove(card);
            return card;
        }

        public void Shuffle()
        {
            _CardsLeft = _CardsLeft.OrderBy(i => Guid.NewGuid()).ToList();
        }

        public void PrintDeck()
        {
            foreach (var card in _CardsLeft)
            {
                Console.WriteLine(card.Rank);
            }
        }
    }
}
